package com.ant.storage.controller;

import com.ant.storage.common.ResultVo;
import com.ant.storage.common.aop.BusinessType;
import com.ant.storage.common.aop.Log;
import com.ant.storage.pojo.Menu;
import com.ant.storage.service.IMenuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
@Api(tags = "菜单接口")
public class MenuController {

    @Autowired
    IMenuService menuService;

//    @Log(operation = "查询菜单列表",businessType= BusinessType.LIST)
    @ApiOperation(value = "获取员工列表")
    @GetMapping("/queryMenuList")
    public ResultVo queryMenuList() {
        return ResultVo.success("操作成功",menuService.menuList());
    }

    @ApiOperation(value = "获取员工列表")
    @GetMapping("/findMenuList")
    public ResultVo findMenuList() {
        List<Menu> list = menuService.list(new QueryWrapper<Menu>().eq("parent_id",0));
        return ResultVo.success("操作成功",list);
    }


    @Log(operation = "添加或修改菜单",businessType= BusinessType.INSERT)
    @ApiOperation(value = "添加角色")
    @PostMapping("/saveMenu")
    public ResultVo saveRole(@RequestBody Menu menu) {
        if(menu.getTitle() == null || menu.getTitle().trim().equals("")){
            return ResultVo.failure(201,"名称不能为空");
        }
        if(menu.getName() == null || menu.getName().trim().equals("")){
            return ResultVo.failure(201,"值不能为空");
        }
        if (menu.getId() == null) {
            menuService.save(menu);
        } else {
            menuService.updateById(menu);
        }
        return ResultVo.success("操作成功");
    }

}
